(function() {
    $('form').validate({
        rules: {
            accounts: 'required',
            pwd: 'required'
        },
        messages: {
            accounts: '请输入用户名',
            pwd: '请输入密码'
        },
        submitHandler: function(form) {
            var params = {
                accounts: form.accounts.value,
                pwd: form.pwd.value
            }

            $.ajax({
                url: 'index.php?s=/index/user/login',
                type: 'post',
                dataType: 'json',
                data: params,
                success: function(res) {
                    if (res.code == 0) {
                        window.location.href = "index.php?s=/index/user/center.html";
                    } else {
                        layer.msg(res.msg);
                    }
                },
                error: function() {
                    layer.msg("连接服务器失败");
                }
            });
        }
    });
})();